﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raven.Client.Document;

namespace SVNUG.Presentations.NoSql.Business
{

    /// <summary>
    /// Singleton
    /// </summary>
    public class RavenDbContext
    {
        private static Object _synchronizingObject = new object();
        private static RavenDbContext _instance = null;

        private DocumentStore _documentStore = new DocumentStore();

        public static RavenDbContext Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_synchronizingObject)
                    {
                        if (_instance == null)
                        {
                            _instance = new RavenDbContext();
                        }
                    }
                }

                return _instance;
            }
        }
        private RavenDbContext()
        {
            this._documentStore = this.CreateDocumentStore();
        }

        public DocumentStore Store
        {
            get
            {
                return this._documentStore;
            }
        }
        private DocumentStore CreateDocumentStore()
        {
            var documentStore = new DocumentStore { Url = "http://localhost:8080/"};

            documentStore.Initialize();

            return documentStore;
        }
    }
}
